// src/pages/catering/memberCenter/memberCenter.js
import getIn from '../../../../yali-sdk/utils/getIn';
import { getImagePath, showFail, showSuccess } from '../../../config/common';
import getFrontMemberInfo from '../../../../yali-sdk/business/member/fetchMemberInfo';
import { SUCCESS } from '../../../../yali-sdk/utils/success';
import { FAIL } from '../../../../yali-sdk/utils/fail';
import {
  ORDER_TYPE_CATERING, // 餐饮
  ORDER_TYPE_HOTEL, // 酒店
  ORDER_TYPE_OTHER, // 其他
} from '../../../../yali-sdk/business/order/constrants.js';
import { 
  COUPON_MY_LIST_PATH, 
  CATERING_MY_QUEUE, 
  CATERING_ORDER_LIST, 
  MEMBER_ADDRESS_LIST_PATH,
  CATERING_MY_WALLET,
  } from '../../../pages/pathUrl';
Page({
  data: {
    ORDER_TYPE_CATERING, // 餐饮
    ORDER_TYPE_HOTEL, // 酒店
    ORDER_TYPE_OTHER, // 其他
  },
  onLoad() {
    const token = getIn(getApp(), ['globalData', 'token']);
    global.ActionDispatcher.execute(getFrontMemberInfo, { token }, (status, result) => {
      if (status == SUCCESS) {
        const _user = getIn(result, ['data']);
        const head_photo = getImagePath(getIn(result, ['data', 'head_photo']));
        this.setData({
          _user, head_photo
        });
      } else if (status == FAIL) {
        showFail(result.msg)
      }
    });
  },
  toMyWallet() {
    global.navigateHelper && global.navigateHelper.navigateTo({ pathname: CATERING_MY_WALLET });
  },
  toOrder(e) {
    const shop_template = getIn(e.currentTarget.dataset, ['shop_template']);
    let queryString = ''
    if (shop_template != undefined) {
      queryString = `shop_template=${shop_template}`;
    }
    global.navigateHelper && global.navigateHelper.navigateTo({ pathname: CATERING_ORDER_LIST, queryString });
  },
  toAddress() {
    global.navigateHelper && global.navigateHelper.navigateTo({ pathname: MEMBER_ADDRESS_LIST_PATH });
  }
});